package com.mail.server.controller;


import com.mail.model.db.OmsOrderReturnReason;
import com.mail.model.dto.OrderReturnApplyDto;
import com.mail.model.vo.PageResult;
import com.mail.server.common.R;
import com.mail.server.service.OmsOrderReturnReasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 退货原因表 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {

    @Autowired
    private OmsOrderReturnReasonService orderReturnReasonService;

    /**
     * 分页查询退货原因
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public R list(@RequestParam(defaultValue = "1") Integer pageNum,
                  @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult result = orderReturnReasonService.list(pageNum, pageSize);
        return R.success(result);
    }

    /**
     * 根据id，获取单个退货原因详情信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R select(@PathVariable Long id) {
        OmsOrderReturnReason orderReturnReason = orderReturnReasonService.select(id);
        return R.success(orderReturnReason);
    }

    /**
     * 修改退货原因
     *
     * @param id
     * @return
     */
    @PostMapping("/update/{id}")
    public R updateReturnReason(@PathVariable Long id, @RequestBody OmsOrderReturnReason reason) {
        Integer count = orderReturnReasonService.updateReturnReason(id, reason);
        if (count == null) {
            return R.error("修改失败");
        }
        return R.success("修改成功");
    }

    /**
     * 修改退货原因启用状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status")
    public R updateStatus(@RequestParam("ids") Long id, @RequestParam Integer status) {
        Integer count = orderReturnReasonService.updateStatus(id, status);
        if (count == null) {
            return R.error("修改失败");
        }
        return R.success("修改成功");
    }

    /**
     * 批量删除退货原因
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public R delete(@RequestParam List<Long> ids) {
        Integer count = orderReturnReasonService.delete(ids);
        if (count == null) {
            return R.error("删除失败");
        }
        return R.success("删除成功");
    }

    /**
     * 添加退货原因
     * @param reason
     * @return
     */
    @PostMapping("/create")
    public R create(@RequestBody OmsOrderReturnReason reason) {
        Integer count = orderReturnReasonService.create(reason);
        if (count == null) {
            return R.error("删除失败");
        }
        return R.success("删除成功");
    }
}
